package stack_queue.leetcode.Leetcode;

import java.util.Stack;

/**
 * @author shkstart
 * @create 2022-10-12-17:28
 */
public class MyQueue232 {
    private Stack<Integer> data;
    private Stack<Integer> help;

    public MyQueue232() {
        data = new Stack<>();
        help = new Stack<>();
    }

    public void push(int x) {

        if(data.isEmpty()){
            data.push(x);
        }else{
//            1.将data中的元素移动到help中
            while(!data.isEmpty()){
                help.add(data.pop());
            }
            data.add(x);
//            2.将help中的元素出栈移动至data
            while(!help.isEmpty()){
                data.add(help.pop());
            }
        }
    }

    public int pop() {
        return data.pop();
    }

    public int peek() {
        return data.peek();
    }

    public boolean empty() {
        return data.isEmpty();
    }
}
